﻿using GNSystem.Filters;
using GNSystem.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebMatrix.WebData;

namespace GNSystem.Controllers
{
    [InitializeSimpleMembership]
    public class AdminController : Controller
    {
        private DataContext db = new DataContext();
        //
        // GET: /Admin/

        public ActionResult Index()
        {
            if (Allow)
            {
                ViewBag.Context = db;
                return View();
            }
            return RedirectToAction("AccessDenied", "Error");
        }

        public ActionResult AddForum()
        {
            return View();
        }

        [HttpPost]
        public ActionResult AddForum(Forum model)
        {
            db.Forums.Add(model);
            db.SaveChanges();
            return RedirectToAction("Index");
        }


        private bool Allow
        {
            get
            {
                return WebSecurity.CurrentUserId > 0 && db.UserGroups.Find(db.UserProfiles.Find(WebSecurity.CurrentUserId).GroupID).IsAdmin;
            }
        }
    }
}
